// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include <cantor/parser/ast/dcl.h>

namespace cantor::parser {

    nlohmann::ordered_json UserIdentity::to_json() const {
        auto j = DefiniteExpr::to_json_impl();
        j["username"] = username.to_string();
        j["hostname"] = hostname.to_string();
        j["current_user"] = current_user;
        return j;
    }

    nlohmann::ordered_json AuthOption::to_json() const {
        auto j = DefiniteExpr::to_json_impl();
        j["auth_string"] = auth_string.to_string();
        j["hash_string"] = hash_string.to_string();
        j["auth_plugin"] = auth_plugin.to_string();
        return j;
    }

    nlohmann::ordered_json UserSpec::to_json() const {
        auto j = DefiniteExpr::to_json_impl();
        j["user"] = user->to_json();
        j["auth_opt"] = auth_opt->to_json();
        return j;
    }

    nlohmann::ordered_json PrivType::to_json() const {
        auto j = DefiniteExpr::to_json_impl();
        j["type"] = type;
        return j;
    }

    nlohmann::ordered_json PrivLevel::to_json() const {
        auto j = DefiniteExpr::to_json_impl();
        j["level"] = level;
        j["db_name"] = db_name.to_string();
        j["table_name"] = table_name.to_string();
        return j;

    }
}  // namespace cantor::parser
